//
//  StatusCellRetweetedView.swift
//  WeiBo_Private
//
//  Created by Yangperlove on 16/1/20.
//  Copyright © 2016年 Yangperlove. All rights reserved.
//

import UIKit
import SnapKit

class StatusCellRetweetedView: UIView {

    var retweeted_status: Status? {
        didSet {
            retweetedLabel.text = retweeted_status?.text
            retweetedPicture.imageUrls = retweeted_status?.picImageUrls
            bottomConstraint?.uninstall()
            if retweeted_status?.picImageUrls?.count == nil {
                self.snp_updateConstraints(closure: { (make) -> Void in
                    self.bottomConstraint = make.bottom.equalTo(retweetedLabel.snp_bottom).offset(kStatusCellMargin).constraint
                })
                return
            }
            
            self.snp_updateConstraints { (make) -> Void in
                self.bottomConstraint = make.bottom.equalTo(retweetedPicture.snp_bottom).offset(kStatusCellMargin).constraint
            }
        }
    }

    override init(frame: CGRect) {
        super.init(frame: frame)
        backgroundColor = UIColor(white: 0.96, alpha: 1)
        setupUI()
    }

    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    var bottomConstraint: Constraint?
    
    func setupUI() {
        addSubview(retweetedLabel)
        addSubview(retweetedPicture)
        
        retweetedLabel.snp_makeConstraints { (make) -> Void in
            make.top.left.right.equalTo(self)
        }
        
        retweetedPicture.snp_makeConstraints { (make) -> Void in
            make.top.equalTo(retweetedLabel.snp_bottom).offset(kStatusCellMargin)
            make.left.equalTo(retweetedLabel)
        }
        
        self.snp_makeConstraints { (make) -> Void in
            bottomConstraint = make.bottom.equalTo(retweetedPicture.snp_bottom).constraint
        }
        
    }
    
    
    lazy var retweetedLabel: UILabel = UILabel(title: "hahahaha", color: UIColor.lightGrayColor(), fontSize: 14, margin: kStatusCellMargin)
    lazy var retweetedPicture: StatusPictureView = StatusPictureView()
}
